<template>
	<view>
		<view class="search-Box">
		<My-search ></My-search>
		</view>
		
        <swiper :indicator-dots="true" :duration="1000" :autoplay="true" :interval="3000" :circular="true">
			<swiper-item v-for="(item,i) in swiperList" :key="i">

				<view class="swiper-item" :url='"/subpkg/goods_detail/goods_detail?goods_id="+item.goods_id'>
					<image  :src="item.image_src"></image>
				</view>
			</swiper-item>
		</swiper>
		
		<view class="navList">
			 		<view class="nav-item" v-for="(item,i) in navList" :key="i" @click="navClick(item)">
			 			<image class="swiper-item" :src="item.image_src"></image>
			 		</view>
			 </swiper>
		</view>
		<view class="flootList">
			 <view class="floot-item" v-for="(item,i) in flootList" :key="i">
				  <image :src="item.floor_title.image_src" class="floot-img"></image>
			  <view class="flootBox-left">
				  <navigator class="left" :url="item.product_list[0].url">
					  <image :src="item.product_list[0].image_src"  :style="{width:item.product_list[0].image_width+'rpx'}"  mode="widthFix"></image>
				  </navigator>
				  <view class="right">
				  <navigator :url="item2.url" class="right-item"  v-if="i2!=0"  v-for="(item2,i2) in item.product_list" :key="i2">  
				 	<image :src="item2.image_src"  mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>	   
				   </navigator>
				  </view>
			  </view>
			 </view>
		
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList:[],
				navList:[],
				flootList:[],
				
			};
		},
		onLoad(){
			this.getSwiperList()
			this.getNavList()
			this.getFooltList()
			
		},
		methods:{
			async getSwiperList(){ //获取轮播图
			 const {data:res}= await uni.$http.get("/api/public/v1/home/swiperdata")
			  if(res.meta.status!==200) return uni.$showMsg("数据请求失败")
			  this.swiperList=res.message
			},
			 async getNavList (){//获取分类
				const {data:res}=await uni.$http.get("/api/public/v1/home/catitems") 
				
			   if(res.meta.status!==200) return uni.$showMsg("数据请求失败")
			   this.navList=res.message
			},
			async getFooltList(){//获取运动图
				const {data:res}=await uni.$http.get("/api/public/v1/home/floordata")
		         if(res.meta.status!==200) return uni.$showMsg("数据请求失败")
				
				  res.message.forEach(floot=>{
					  floot.product_list.forEach(item=>{
						  item.url="/subpkg/goods_list/goods_list?"+item.navigator_url.split("?")[1]
					  })
				  })
				  this.flootList=res.message
			},
			navClick(item){ //判断用户点击是否时分类并跳转
			
				if(item.name==="分类"){
					
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
			},
			setBadge(){
				uni.setTabBarBadge({
					index:2,
					text:uni.$Store.getters.total>0?uni.$Store.getters.total+"":this.removeBadge()
				})
			},
			removeBadge(){
				uni.removeTabBarBadge({
					index:2
				})
				
			}
		},
		onShow(){
			this.setBadge()
		}
	}
</script>

<style lang="scss">
swiper{
	height:330rpx;
	.swiper-item,
		image{
			width:100%;
			height:100%;
		
	}
},
.navList{
	display: flex;
	 justify-content:space-around;
     margin:15px 0;
.swiper-item{
		height:148rpx;
		width:128rpx;
	}
}

	.floot-img{
		width:100%;
		height:60rpx;
	}
	.flootBox-left{
		display: flex;
		margin-left:10rpx;
		.right {
			display: flex;
			flex-wrap: wrap;
			image{
			  padding:0 10rpx;
			}
		}
		
	}
.search-Box{
	position:sticky;
	z-index: 999;
	top:0
}
</style>
